// pages/map/add/add.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		region: ['请选择', '', ''],
		isChecked: false,
		iphone: '',
		name: '',
		city: ''
	},
	name1(e) {
		this.setData({
			name: e.detail.value
		})
	},
	city1(e) {
		this.setData({
			city: e.detail.value
		})
	},
	iphone1(e) {
		this.setData({
			iphone: e.detail.value
		})
	},
	bindRegionChange: function(e) {
		console.log('picker发送选择改变，携带值为', e.detail.value)
		this.setData({
			region: e.detail.value
		})
	},
	changeSwitch(e) {
		console.log(e.detail.value)
		this.setData({
			isChecked: e.detail.value
		})
	},
	sure() {
		if(this.data.name!=''&& this.data.iphone!=''&& this.data.city!=''&&this.data.region[0]!='请选择'){
			wx.getStorage({
				key: 'uid',
				success: (e) => {
					wx.request({
						url: getApp().globalData.http + 'action=addAddress&uname='
						+this.data.name + '&mobile=' + this.data.iphone + '&uid=' + e.data.uid +
						'&prov=' + this.data.region[0] + '&city=' + this.data.region[1] +
						'&county=' + this.data.region[2] + '&address=' + this.data.city + '&isDefault=' + this.data.isChecked,
						success: (res) => {
							console.log(res)
							let pages = getCurrentPages(); // 当前页的数据，可以输出来看看有什么东西
							let prevPage = pages[pages.length - 3];
							console.log(prevPage.route)
								prevPage.setData({
									add: res.data.data,
									pd:0,
								})
							wx.navigateBack({
								delta:1
							})
						}
					})
				}
			})
		}else{
			wx.showToast({
				title:'请正确填写资料',
				icon:'none'
			})
		}
		

	}
})
